package svc.elib.lookup;

import java.io.IOException;
import java.util.Iterator;
import java.util.LinkedList;

import svc.elib.db.Author;
import svc.elib.db.Database;
import svc.elib.socnet.ConnectedComponents;
import svc.elib.socnet.Net;
import svc.elib.socnet.SocConstructor;

public class NetworkedCorrector extends NameSimilarity {
	
	private Net net;

	public NetworkedCorrector(Net net) {
		super();
		this.net = net;
	}
	
	public void similarNamesInComponents() {
		ConnectedComponents cs = new ConnectedComponents(net);
		cs.resolveComponents();
		LinkedList<Net> comps = cs.getComponents();
		for (Net comp : comps) {
			LinkedList<String> names = new LinkedList<String>();
			Iterator<Author> ait = comp.getGraph().getVertices().iterator();
			while (ait.hasNext()) {
				String name = ait.next().getName();
				names.add(name);
			}
			
			checkSimilar(names);
		}
		
		dumpResults();
	}
	
	
	public static void main(String[] args) 
		throws IOException
	{
		Database db = new Database("eLibData.csv", 1932, 2011);
		System.out.println(db.info());
		SocConstructor soc = new SocConstructor(db);
		Net net = soc.getNet();
		NetworkedCorrector nc = new NetworkedCorrector(net);
		nc.similarNamesInComponents();
	}
	
}
